/// 风筝时刻评论实体模型
class KiteMomentCommentEntity {
  /// 唯一标识符
  final String uniqueIdentifier;

  /// 所属风筝时刻ID
  final String momentIdentifier;

  /// 评论者ID
  final String authorIdentifier;

  /// 评论内容
  final String commentContent;

  /// 评论时间
  final DateTime publishTimestamp;

  const KiteMomentCommentEntity({
    required this.uniqueIdentifier,
    required this.momentIdentifier,
    required this.authorIdentifier,
    required this.commentContent,
    required this.publishTimestamp,
  });

  /// 创建空实例
  factory KiteMomentCommentEntity.createEmptyInstance() {
    return KiteMomentCommentEntity(
      uniqueIdentifier: '',
      momentIdentifier: '',
      authorIdentifier: '',
      commentContent: '',
      publishTimestamp: DateTime.now(),
    );
  }

  /// 从Map数据创建实例
  factory KiteMomentCommentEntity.fromDataMap(Map<String, dynamic> dataMap) {
    return KiteMomentCommentEntity(
      uniqueIdentifier: dataMap['uniqueIdentifier']?.toString() ?? '',
      momentIdentifier: dataMap['momentIdentifier']?.toString() ?? '',
      authorIdentifier: dataMap['authorIdentifier']?.toString() ?? '',
      commentContent: dataMap['commentContent']?.toString() ?? '',
      publishTimestamp:
          DateTime.tryParse(dataMap['publishTimestamp']?.toString() ?? '') ??
          DateTime.now(),
    );
  }

  /// 转换为Map数据
  Map<String, dynamic> convertToDataMap() {
    return {
      'uniqueIdentifier': uniqueIdentifier,
      'momentIdentifier': momentIdentifier,
      'authorIdentifier': authorIdentifier,
      'commentContent': commentContent,
      'publishTimestamp': publishTimestamp.toIso8601String(),
    };
  }

  /// 检查实例是否为空
  bool validateEmptyState() {
    return uniqueIdentifier.isEmpty || commentContent.isEmpty;
  }

  @override
  String toString() {
    return 'KiteMomentCommentEntity{id: $uniqueIdentifier, momentId: $momentIdentifier, author: $authorIdentifier}';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is KiteMomentCommentEntity &&
        other.uniqueIdentifier == uniqueIdentifier;
  }

  @override
  int get hashCode {
    return uniqueIdentifier.hashCode;
  }

  /// 预定义的评论数据集合
  static final List<KiteMomentCommentEntity> _predefinedCommentCollection = [
    // moment_img_001 的评论 (5条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_001_01',
      momentIdentifier: 'moment_img_001',
      authorIdentifier: 'kite_user_002',
      commentContent:
          'Love the fashion-forward approach to kite flying! That coat is amazing! 🌈',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 1, hours: 12),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_001_02',
      momentIdentifier: 'moment_img_001',
      authorIdentifier: 'kite_user_003',
      commentContent: 'The sky really is the perfect runway! Beautiful shot 📸',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 1, hours: 8),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_001_03',
      momentIdentifier: 'moment_img_001',
      authorIdentifier: 'kite_user_005',
      commentContent:
          'This is why I love our kite community - creativity everywhere! 🎨',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 1, hours: 4),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_001_04',
      momentIdentifier: 'moment_img_001',
      authorIdentifier: 'kite_user_007',
      commentContent: 'Fashion meets flight - what a perfect combination! ✨',
      publishTimestamp: DateTime.now().subtract(const Duration(hours: 18)),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_001_05',
      momentIdentifier: 'moment_img_001',
      authorIdentifier: 'kite_user_008',
      commentContent: 'That rainbow kite matches your energy perfectly! 🪁',
      publishTimestamp: DateTime.now().subtract(const Duration(hours: 6)),
    ),

    // moment_img_002 的评论 (4条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_002_01',
      momentIdentifier: 'moment_img_002',
      authorIdentifier: 'kite_user_001',
      commentContent:
          'These family moments are pure gold! The golden hour makes it even more magical ✨',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 4, hours: 10),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_002_02',
      momentIdentifier: 'moment_img_002',
      authorIdentifier: 'kite_user_004',
      commentContent:
          'Nothing beats simple joys like this. Beautiful family time! 👨‍👩‍👧‍👦',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 4, hours: 6),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_002_03',
      momentIdentifier: 'moment_img_002',
      authorIdentifier: 'kite_user_006',
      commentContent:
          'The way you captured the light and laughter is perfect! 📷',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 3, hours: 14),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_002_04',
      momentIdentifier: 'moment_img_002',
      authorIdentifier: 'kite_user_008',
      commentContent:
          'This is what happiness looks like! Thanks for sharing 😊',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 3, hours: 8),
      ),
    ),

    // moment_img_003 的评论 (3条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_003_01',
      momentIdentifier: 'moment_img_003',
      authorIdentifier: 'kite_user_002',
      commentContent:
          'Kids and kites - the perfect combination! He looks so focused 👦',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 6, hours: 12),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_003_02',
      momentIdentifier: 'moment_img_003',
      authorIdentifier: 'kite_user_005',
      commentContent:
          'Teaching them young! Love seeing the next generation of kite flyers 🪁',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 6, hours: 8),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_003_03',
      momentIdentifier: 'moment_img_003',
      authorIdentifier: 'kite_user_007',
      commentContent: 'The determination in his little hands is so sweet! 💪',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 5, hours: 16),
      ),
    ),

    // moment_img_004 的评论 (5条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_004_01',
      momentIdentifier: 'moment_img_004',
      authorIdentifier: 'kite_user_001',
      commentContent:
          'That parrot kite is absolutely stunning! Perfect match with your dress 🦜',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 9, hours: 14),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_004_02',
      momentIdentifier: 'moment_img_004',
      authorIdentifier: 'kite_user_003',
      commentContent:
          'Fashion and flight - you nailed it! The beach setting is perfect 🌊',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 9, hours: 10),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_004_03',
      momentIdentifier: 'moment_img_004',
      authorIdentifier: 'kite_user_006',
      commentContent:
          'Love how you embrace the wild, colorful energy! Inspiring! 🎨',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 8, hours: 18),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_004_04',
      momentIdentifier: 'moment_img_004',
      authorIdentifier: 'kite_user_007',
      commentContent:
          'The freedom to soar - beautifully captured in words and image! ✨',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 8, hours: 12),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_004_05',
      momentIdentifier: 'moment_img_004',
      authorIdentifier: 'kite_user_008',
      commentContent: 'Your spirit animal found you! What a magical moment 🪁',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 8, hours: 6),
      ),
    ),

    // moment_img_005 的评论 (3条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_005_01',
      momentIdentifier: 'moment_img_005',
      authorIdentifier: 'kite_user_002',
      commentContent:
          'These golden hour family moments are everything! So peaceful 🌅',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 11, hours: 16),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_005_02',
      momentIdentifier: 'moment_img_005',
      authorIdentifier: 'kite_user_004',
      commentContent: 'Home is wherever your family is - beautifully said! 💕',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 11, hours: 8),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_005_03',
      momentIdentifier: 'moment_img_005',
      authorIdentifier: 'kite_user_006',
      commentContent: 'The ocean, the giggles, the sunset - pure magic! 🌊',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 10, hours: 20),
      ),
    ),

    // moment_img_006 的评论 (4条)
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_006_01',
      momentIdentifier: 'moment_img_006',
      authorIdentifier: 'kite_user_001',
      commentContent:
          'LED kites are the future! This looks absolutely magical ✨',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 14, hours: 12),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_006_02',
      momentIdentifier: 'moment_img_006',
      authorIdentifier: 'kite_user_003',
      commentContent:
          'Night flying just got a whole lot cooler! Amazing innovation 🌙',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 14, hours: 8),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_006_03',
      momentIdentifier: 'moment_img_006',
      authorIdentifier: 'kite_user_005',
      commentContent: 'The dark sky makes those lights pop! Brilliant idea 💡',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 13, hours: 18),
      ),
    ),
    KiteMomentCommentEntity(
      uniqueIdentifier: 'comment_006_04',
      momentIdentifier: 'moment_img_006',
      authorIdentifier: 'kite_user_007',
      commentContent:
          'I need to try this! Where did you get the LED strips? 🪁',
      publishTimestamp: DateTime.now().subtract(
        const Duration(days: 13, hours: 10),
      ),
    ),
  ];

  /// 根据ID查找预定义的评论数据
  static KiteMomentCommentEntity? findCommentByIdentifier(String targetId) {
    try {
      return _predefinedCommentCollection.firstWhere(
        (comment) => comment.uniqueIdentifier == targetId,
      );
    } catch (e) {
      return null;
    }
  }

  /// 根据风筝时刻ID获取评论列表
  static List<KiteMomentCommentEntity> getCommentsByMomentId(String momentId) {
    return _predefinedCommentCollection
        .where((comment) => comment.momentIdentifier == momentId)
        .toList();
  }

  /// 根据作者ID获取评论列表
  static List<KiteMomentCommentEntity> getCommentsByAuthor(String authorId) {
    return _predefinedCommentCollection
        .where((comment) => comment.authorIdentifier == authorId)
        .toList();
  }

  /// 获取所有预定义的评论数据
  static List<KiteMomentCommentEntity> getAllPredefinedComments() {
    return List.unmodifiable(_predefinedCommentCollection);
  }

  /// 添加评论到预定义集合（用于运行时添加）
  static void addCommentToCollection(KiteMomentCommentEntity comment) {
    _predefinedCommentCollection.add(comment);
  }

  /// 从预定义集合中移除评论
  static bool removeCommentFromCollection(String commentId) {
    final index = _predefinedCommentCollection.indexWhere(
      (comment) => comment.uniqueIdentifier == commentId,
    );
    if (index != -1) {
      _predefinedCommentCollection.removeAt(index);
      return true;
    }
    return false;
  }
}
